/**
 * AnyStream
 * Copyright (C) 2021 AnyStream Maintainers
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package anystream

import anystream.test.RESOURCES
import com.typesafe.config.ConfigFactory
import com.typesafe.config.ConfigValueFactory
import io.ktor.client.request.*
import io.ktor.http.HttpStatusCode
import io.ktor.server.config.*
import io.ktor.server.testing.*
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

class ApplicationTest {
    private val testEnv = createTestEnvironment {
        config = HoconApplicationConfig(
            ConfigFactory.load("application.conf")
                .withValue("app.webClientPath", ConfigValueFactory.fromAnyRef("$RESOURCES/static")),
        )
    }

    @Ignore("server configuration error")
    @Test
    fun testApiRootRedirectsToFrontEnd() {
        testApplication {
            val response = client.get("/api")
            assertEquals(HttpStatusCode.Found, response.status)
            assertEquals("/", response.headers["location"])
        }
    }
}
